﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>


int add(int a, int b)
{
	return a + b;
}
int sub(int a, int b)
{
	return a - b;
}
int mult(int a, int b)
{
	return a * b;
}
int div(int a, int b)
{
	return a / b;
}

int main()
{
	int input = 0;
	int a = 0, b = 0;
	int ret = 0;
	int (*p[5])(int a, int b) = { 0,add,sub,mult,div };
	do
	{
		printf("*************************\n");
		printf("****** 1:add 2:sub ******\n");
		printf("****** 3:mul 4:div ******\n");
		printf("****** 0:exit      ******\n");
		printf("请选择：");
		scanf("%d", &input);
		if ((input <= 4 && input >= 1))
		{
			printf("输入操作数：");
			scanf("%d %d", &a, &b);
			ret = (*p[input])(a, b);
			printf("ret = %d\n", ret);
		}
		else if (input == 0)
		{
			printf("退出计算器\n");
		}
		else
		{
			printf("输入有误\n");
		}



	} while (input);

	return 0;
}